<template>
	<div class="myTask_list">
		<mu-list>
		    <mu-sub-header>今日完成任务</mu-sub-header>
		    <mu-list-item v-for="list in taskList1" :title="list.taskContent">
		    	<span class="typeCircle" :style="'background:' + $store.state.taskLevelColor[list.taskLevel]" slot="leftAvatar">
		    		{{$store.state.taskLevel[list.taskLevel]}}</span>
		    	<mu-icon value="check_circle" :color="$store.state.taskStatusColor[list.taskStatus]" slot="right"/>
		    	<label class="col_warning">审核人：{{mobileToName(list.examine)}}</label>
		    </mu-list-item>
		</mu-list>
		<mu-divider/>
		<mu-list>
		    <mu-sub-header>七天内完成任务</mu-sub-header>
		    <mu-list-item v-for="list in taskList7" :title="list.taskContent">
		    	<span class="typeCircle" :style="'background:' + $store.state.taskLevelColor[list.taskLevel]" slot="leftAvatar">
		    		{{$store.state.taskLevel[list.taskLevel]}}</span>
		    	<mu-icon value="check_circle" :color="$store.state.taskStatusColor[list.taskStatus]" slot="right"/>
		    	<label class="col_warning">审核人：{{mobileToName(list.examine)}}</label>
		    </mu-list-item>
		</mu-list>
		<mu-divider/>
		<mu-list>
		    <mu-sub-header>30天内完成任务</mu-sub-header>
		    <mu-list-item v-for="list in taskList30" :title="list.taskContent">
		    	<span class="typeCircle" :style="'background:' + $store.state.taskLevelColor[list.taskLevel]" slot="leftAvatar">
		    		{{$store.state.taskLevel[list.taskLevel]}}</span>
		    	<mu-icon value="check_circle" :color="$store.state.taskStatusColor[list.taskStatus]" slot="right"/>
		    	<label class="col_warning">审核人：{{mobileToName(list.examine)}}</label>
		    </mu-list-item>
		</mu-list>
	</div>
</template>

<script>
import axios from 'axios'
export default{
	data(){
		return {
			userList: this.$store.state.userList,
			taskList1: [],
			taskList7: [],
			taskList30: [],
		}
	},
	methods: {
		getTaskComplete(){
			let params = {
					mobile: this.$store.state.userInfo.mobile,
					days: new Date(moment(new Date()).format('YYYY-MM-DD')).getTime() - 86400000*30
				};

			axios.post($base + 'task/getTaskComplete', params).then(json => {
				json.data.forEach(e => {
					let tDate = moment(new Date()).format('YYYY-MM-DD'),
						cDate = moment(e.completeDate).format('YYYY-MM-DD');
					switch(true){
						case tDate == cDate:
							this.taskList1.push(e);
							break;
						case cDate < tDate && cDate >= moment(new Date().getTime() - 86400000*7).format('YYYY-MM-DD'):
							this.taskList7.push(e);
							break;
						default:
							this.taskList30.push(e);
							break;
					}
				})
			}).catch(json => {
				console.log(json)
			})
		},
		//通过手机获取用户名
		mobileToName(mobile){
			let name = '';
			this.userList.map(list => {
				if(list.mobile == mobile){
					name = list.userName;
				}
			})
			return name;
		}
	},
	mounted(){
		this.getTaskComplete();
	}
}
</script>